/** WPI CS509 Cisco Stratego Message Base Class.
 *  This class specifies serializable. 
 */
package edu.wpi.cs509.messages;

import java.io.Serializable;

import edu.wpi.cs509.network.Connection;

/** Message base class. This is an abstract class that provides 
 * the basic message function: rxExecute.
 * @author sparadis
 *
 */
public abstract class MsgBc implements Serializable {

	/**
	 * serializable version number
	 */
	private static final long serialVersionUID = 1L;
	
	/** The connection on which the message arrived. 
	 * This is not sent over the wire. 
	 */
	private transient Connection connection;

	/** 
	 * Constructor, empty so far.
	 */
	public MsgBc() {
	}
	
	/**
	 * rxExecute: This function executes the message.
	 * 
	 * @return null
	 */
	abstract public void rxExecute();

	/**
	 * @return The connection on which the message arrived.
	 */
	public Connection getConnection() {
		return connection;
	}
	
	/**
	 * Used by the networking layer to set the connection after 
	 * the message has arrived.
	 * 
	 * @param connection The connection on which the message arrived.
	 */
	public void setConnection(Connection connection) {
		this.connection = connection;
	}
	
	/**
	 * Send the reply message to the source of this message.
	 * 
	 * @param reply: reply message for this request message.
	 */
	public void sendReply(MsgBc reply) {
			getConnection().sendMessage(reply);
	}
}
